package com.yneusoft.pctask.controller;

import com.alibaba.fastjson.JSON;
import com.yneusoft.common.model.ResponseWrapper;
import com.yneusoft.dao.entity.Department;
import com.yneusoft.pctask.model.*;
import com.yneusoft.pctask.service.DepartmentManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description： 部门管理controller
 * @Author: wbf
 * @Date: 2021/11/24 14:12
 */
@RestController
@CrossOrigin
@RequestMapping("/departmentManage")
public class DepartmentManageController {
    @Autowired
    DepartmentManageService departmentManageService;
    /**
     * 1.获取部门状态列表
     * @return 部门状态列表
     */
    @GetMapping("/getDepartmentStateList")
    public ResponseWrapper getDepartmentStateList(){
        return departmentManageService.getDepartmentStateList();
    }

    /**
     * 2.获取部门列表
     * @return 部门列表
     */
    @GetMapping("/getDepartmentList")
    public ResponseWrapper getDepartmentList(@Validated GetDepartmentListParam param){
        return departmentManageService.getDepartmentList(param);
    }

    /**
     * 3、【新增/修改】启用/禁用部门
     * @return 修改状态
     */
    @PostMapping("/enableDepartment")
    public ResponseWrapper enableDepartment(@Validated @RequestBody EnableDepartmentParam param){
        System.out.println("测试"+param.toString());
        return departmentManageService.enableDepartment(param);
    }

    /**
     * 4、【新增/修改】修改时获取的部门信息
     * @return 部门信息
     */
    @GetMapping("/getDepartmentInfo")
    public ResponseWrapper getDepartmentInfo(@Validated GetDepartmentInfoParam param){
        return departmentManageService.getDepartmentInfo(param);
    }

    /**
     * 5、【新增/修改】修改时获取部门列表
     * @return 部门列表
     */
    @GetMapping("/getDepartmentInfoList")
    public ResponseWrapper getDepartmentInfoList(){
        return departmentManageService.getDepartmentInfoList();
    }

    /**
     * 6、【新增/修改】新增/修改部门信息
     * @param param 表单信息
     * @return 修改情况
     */
    @PostMapping("/saveDepartmentInfo")
    public ResponseWrapper saveDepartmentInfo(@Validated @RequestBody SaveDepartmentInfoParam param){
        return departmentManageService.saveDepartmentInfo(param);
    }

    /**
     * 7、【新增/修改】检查部门名称是否重复
     * @param param 部门aid和name
     * @return isExist
     */
    @GetMapping("/checkDepartmentNameExist")
    public ResponseWrapper checkDepartmentNameExist(@Validated CheckDepartmentNameExistParam param){
        return departmentManageService.checkDepartmentNameExist(param);
    }

    /**
     * 8、【删除】删除部门
     * @param param 部门aid
     * @return 操作结果
     */
    @PostMapping("/delDepartment")
    public ResponseWrapper delDepartment(@Validated @RequestBody DelDepartmentParam param){
        return departmentManageService.delDepartment(param);
    }

    /**
     * 9、检查部门父子关系
     * @param param 父部门aid和子部门aid
     * @return 能否关联
     */
    @GetMapping("/checkDepartmentRelate")
    public ResponseWrapper checkDepartmentRelate(@Validated CheckDepartmentRelateParam param){
        System.out.println(param);
        return departmentManageService.checkDepartmentRelate(param);
    }
}
